<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- ref 放到标签上，可以获取该标签的DOM节点，可以做DOM操作 -->
    <div ref="oDiv">哈哈哈</div>
    <!-- ref 放到组件上，可以获取该组件实例，这样，父组件就可以直接使用子组件的属性和方法 -->
    <my-com ref="com"></my-com>

    <button @click="getData">获取值</button>
  </div>
</body>
<template id="com">
  <div>

  </div>
</template>
<script src="lib/vue.js"></script>
<script>
  const Com = {
    template: '#com',
    data () {
      return {
        msg: 'hello com'
      }
    },
    methods: {
      fn () {
        console.log('子组件')
      }
    }
  }
  new Vue({
    el: '#app',
    components: {
      'my-com': Com
    },
    methods: {
      getData () {
        console.log(this.$refs.oDiv.innerHTML)
        this.$refs.oDiv.style.color = "red"
        this.$refs.com.fn()
        console.log(this.$refs.com.msg)

      }
    }
  })
</script>
</html>